from datetime import datetime

from flask import Blueprint, request, session
from flask_restful import Api, Resource, marshal_with
from flask_restful.reqparse import RequestParser

from utils.render import json_detail_render
from webapp.config import api_utils
from webapp.config.api_utils import oper_log, check_auth
from webapp.dto_mapper import session_page_fields
from webapp.schema import SessionSchema
from webapp.service.session_service import SessionService

wx_session_app = Blueprint('wxsession', __name__, url_prefix='/wxapi/session')
wx_session_api = Api(wx_session_app)

parser = RequestParser()
parser.add_argument('id', location='json', type=int, trim=True, required=True)
parser.add_argument('session', location='json', type=str, trim=True, required=True)
parser.add_argument('begin_date', location='json', type=str, trim=False, required=True)
parser.add_argument('end_date', location='json', type=str, trim=False, required=True)
parser.add_argument('weeksum', location='json', type=str, trim=False, required=True)


@wx_session_api.resource("", "/")
class SessionWxApi(Resource):

    @marshal_with(session_page_fields)
    def get(self):
        params = request.args.items(multi=True)
        params_dict = api_utils.build_params(params)
        return SessionService.query_all(**params_dict)





